package com.samsung.controller.lottery;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.samsung.common.annotation.LoginAuth;
import com.samsung.model.common.Page;
import com.samsung.model.lottery.LotteryEvent;
import com.samsung.service.lottery.LotteryService;


@Controller
@RequestMapping("/lottery")
public class LotteryIndexController {
	@Autowired
	private LotteryService lotteryService;

	/**
	 * 
	 * @Title: index
	 * @Description: TODO(获取最新抽奖信息)
	 * @param @param request
	 * @param @param response
	 * @param @param model
	 * @param @return 设定文件
	 * @return ModelAndView 返回类型
	 * @throws
	 */
	@LoginAuth
	@RequestMapping({"/index", "/"})
	public ModelAndView index(ModelAndView model, HttpServletRequest request) {
		Page page = null;
		
		//默认获取条数
		@SuppressWarnings("unused")
		int max = 5;
		
		String pageNow = request.getParameter("pageNow");
		int totalCount = lotteryService.getTotalCount("");
		
		if(pageNow!=null){
			page = new Page(totalCount, Integer.parseInt(pageNow));
		}else{
			page=new Page(totalCount, 1);
		}
		List<LotteryEvent> lotteryInfo = lotteryService.getPageInfo(page.getStartPos(),page.getPageSize());
		model.addObject("page",page);
		model.addObject("lotteryList", lotteryInfo);
		model.setViewName("lottery/index");
		return model;
	}

}
